package com.haolijun.eecms.service.impl;

import com.haolijun.eecms.common.R;
import com.haolijun.eecms.dao.TbFacilityDao;
import com.haolijun.eecms.entity.TbFacility;
import com.haolijun.eecms.service.FacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName FacilityServiceImpl
 * @Description TODO
 * @Author hljstart
 * @Date 2023/3/12 14:45
 * @Version 1.0
 */
@Service
public class FacilityServiceImpl implements FacilityService {

    @Autowired
    private TbFacilityDao facilityDao;

    @Override
    public R searchFacilityByPage(HashMap param) {
        // 1、 获取当前页数
        int page = (int) param.get("page");
        // 2、获取每一页的记录数
        int length = (int) param.get("length");
        // 3、计算出当前的要开始的页数
        int start = (page - 1) * length;
        // 4、放入到集合中
        param.put("start", start);
        // 5、获取总记录数
        long count = facilityDao.searchFacilityCount(param);
        // 6、获取用户信息
        List<HashMap> facilitys = facilityDao.searchFacilityByPage(param);
        // 7、封装数据
        R r = R.ok().data("totalCount", count).data("pageSize", length).data("pageIndex", start).data("facilitys", facilitys);
        // 8、返回
        return r;
    }

    @Override
    public int insert(TbFacility facility) {
        return facilityDao.insert(facility);
    }

    @Override
    public int delete(Integer id) {
        return facilityDao.delete(id);
    }

    @Override
    public int update(TbFacility facility) {
        return facilityDao.update(facility);
    }

    @Override
    public HashMap searchFacilityInfo(Integer id) {
        return facilityDao.searchFacilityInfo(id);
    }

    @Override
    public int updateFacilityStatus(Integer id,Integer status) {
        HashMap param =  new HashMap();
        param.put("id", id);
        param.put("status", status);
        return facilityDao.updateFacilityStatus(param);
    }


}
